package com.example.crm.controller;

import com.example.crm.service.CustomerService;
import com.example.crm.service.OpportunityService;
import com.example.crm.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 数据分析控制器
 */
@Controller
@RequestMapping("/analytics")
public class AnalyticsController {

    @Autowired
    private CustomerService customerService;
    
    @Autowired
    private OpportunityService opportunityService;
    
    @Autowired
    private ContractService contractService;

    /**
     * 数据分析页面
     */
    @GetMapping
    public String analytics() {
        return "analytics/index";
    }
    
    /**
     * 获取所有统计数据
     */
    @GetMapping("/data")
    @ResponseBody
    public Map<String, Object> getData() {
        Map<String, Object> data = new HashMap<>();
        
        // 获取客户统计数据
        data.put("customer", customerService.getCustomerStatistics());
        
        // 获取销售机会统计数据
        data.put("opportunity", opportunityService.getSalesStatistics());
        
        // 获取合同统计数据
        data.put("contract", contractService.getContractStatistics());
        
        return data;
    }
} 